package com.iheima.reggie_take.util;

/**
 * Created with IntelliJ IDEA.
 * ClassName: SendMessage
 * Package: com.iheima.reggie_take.util
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-01-18
 * Time: 22:08
 */


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 短信发送工具类
 */
public class SMSUtils {

    /**
     * 发送短信
     * @param signName 签名
     * @param templateCode 模板
     * @param phoneNumbers 手机号
     * @param param 参数
     */
    public static void sendMessage(String signName, String templateCode,String phoneNumbers,String param){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t9C4CRYW1vNrXhWyFPP", "1KTWWid87xOZ04tyr76eEmT1b5tRT2");
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setRegionId("cn-hangzhou");
        //给哪个手机号发送短信
        request.setPhoneNumbers(phoneNumbers);
        //签名
        request.setSignName(signName);
        //模板code
        request.setTemplateCode(templateCode);
        request.setTemplateParam("{\"code\":\""+param+"\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println("短信发送成功");
        }catch (ClientException e) {
            e.printStackTrace();
        }
    }
}